package web.suzy.oj.service.msg.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;
import web.suzy.oj.common.exception.StatusFailException;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.manager.msg.AdminNoticeManager;
import web.suzy.oj.pojo.entity.msg.AdminSysNotice;
import web.suzy.oj.pojo.vo.AdminSysNoticeVO;
import web.suzy.oj.service.msg.AdminNoticeService;

import javax.annotation.Resource;

/**
 * YangSuzy 软件工作室
 * 类名: AdminNoticeServiceImpl
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/18 16:45
 */
@Service
public class AdminNoticeServiceImpl implements AdminNoticeService {

    @Resource
    private AdminNoticeManager adminNoticeManager;

    /**
     * 方法名: getSysNotice
     * 描述: 获取系统消息
     *
     * @param limit       每页显示数量
     * @param currentPage 当前页
     * @param type        消息类型
     * @return web.suzy.oj.common.result.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < web.suzy.oj.pojo.vo.AdminSysNoticeVO>>
     * @date 2022/11/18 16:46
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<IPage<AdminSysNoticeVO>> getSysNotice(Integer limit, Integer currentPage, String type) {
        return ResultBean.successResponse(adminNoticeManager.getSysNotice(limit, currentPage, type));
    }

    /**
     * 方法名: addSysNotice
     * 描述: 发布系统消息
     *
     * @param adminSysNotice
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/18 16:55
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<Void> addSysNotice(AdminSysNotice adminSysNotice) {
        try {
            adminNoticeManager.addSysNotice(adminSysNotice);
            return ResultBean.successResponse();
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        }
    }

    /**
     * 方法名: deleteSysNotice
     * 描述: 删除系统消息
     *
     * @param id 消息ID
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/18 17:06
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<Void> deleteSysNotice(Long id) {
        try {
            adminNoticeManager.deleteSysNotice(id);
            return ResultBean.successResponse();
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        }
    }

    /**
     * 方法名: updateSysNotice
     * 描述: 更新系统消息
     *
     * @param adminSysNotice 系统消息
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/18 17:12
     * @auther YangSuzy
     **/
    @Override
    public ResultBean<Void> updateSysNotice(AdminSysNotice adminSysNotice) {
        try {
            adminNoticeManager.updateSysNotice(adminSysNotice);
            return ResultBean.successResponse();
        } catch (StatusFailException e) {
            return ResultBean.errorResponse(e.getMessage());
        }
    }
}
